import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 interface GeneralStack {
	public Object push(Object item);            
	public Object pop();                
	public Object peek();                
	public boolean empty();
	public int size();  
}

class ArrayListGeneralStack implements GeneralStack{
	private List<Object> arraylist=new ArrayList<Object>();
	public Object push(Object item) {
		if(item==null)
		return null;
		arraylist.add(item);
		return item;
	}

	public Object pop() {
		if(arraylist.isEmpty())
		return null;
		return arraylist.remove(arraylist.size()-1);
	}

	public Object peek() {
		if(arraylist.isEmpty())
		return null;
		return arraylist.get(arraylist.size()-1);
	}

	public boolean empty() {
		return arraylist.isEmpty();
	}

	public int size() {
		return arraylist.size();
	}

	public String toString() {
		return arraylist.toString();
	}
	
}
class Car {
	private int id;
	private String name;
	
	public Car(int id, String name) {
		this.id 

 = id;
		this.name 

 = name;
	}

	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id 

 = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name 

 = name;
	}
	
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
	
}
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in );
		while(true) {
		String str=sc.next();
		if(str.equals("quit"))
			return;
		else if(str.equals("Integer")) {
			int m=sc.nextInt();
			int n=sc.nextInt();
			ArrayListGeneralStack stack=new ArrayListGeneralStack();
			System.out.println("\nInteger Test");
			for(int i=0;i<m;i++)
				System.out.println("push:"+stack.push((Integer)sc.nextInt()));
			if(n<m) {
			for(int j=0;j<n;j++)
				System.out.println("pop:"+stack.pop());
			System.out.println(stack.toString());
			int sum=0;
			for(int t=0;t<stack.size();t++) {
				Integer in=(Integer)stack.peek();
				sum+=in.intValue();
				stack.pop();
				t--;
			}
			System.out.println("sum="+sum);
			}
			else if(n>m) {
				for(int i=0;i<m;i++)
					System.out.println("pop:"+stack.pop());
				for(int i=m;i<n;i++)
					System.out.println("pop:null");
				System.out.println("sum=0");
				System.out.println(stack);
			}
			System.out.println(stack.getClass().getInterfaces()[0]);
		}
		else if(str.equals("Double")) {
			int m=sc.nextInt();
			int n=sc.nextInt();
			ArrayListGeneralStack stack=new ArrayListGeneralStack();
			System.out.println("Double Test");
			for(int i=0;i<m;i++)
				System.out.println("push:"+stack.push(sc.nextDouble()));
			if(n<m) {
			for(int j=0;j<n;j++)
				System.out.println("pop:"+stack.pop());
			System.out.println(stack.toString());
			double sum=0.0;
			for(int t=0;t<stack.size();t++) {
				Double in=(Double)stack.peek();
				sum+=in;
				stack.pop();
				t--;
			}
			System.out.println("sum="+sum);
			}
			else if(n>m) {
				for(int i=0;i<m;i++)
					System.out.println("pop:"+stack.pop());
				for(int i=m;i<n;i++)
					System.out.println("pop:null");
				System.out.println("sum=0");
				System.out.println(stack);
			}
			System.out.println(stack.getClass().getInterfaces()[0]);
		}
		else if(str.equals("Car")) {
			int m=sc.nextInt();
			int n=sc.nextInt();
			ArrayListGeneralStack stack=new ArrayListGeneralStack();
			System.out.println("Car Test");
			for(int i=0;i<m;i++)
				System.out.println("push:"+stack.push(new Car(sc.nextInt(), sc.next())));
			if(n<m) {
			for(int j=0;j<n;j++)
				System.out.println("pop:"+stack.pop());
			System.out.println(stack);
			for(int t=0;t<stack.size();t++) {
				Car car=(Car)stack.peek();
				System.out.println(car.getName());
				stack.pop();
				t--;
			}
			}
			else if(n>m) {
				for(int i=0;i<m;i++)
					System.out.println("pop:"+stack.pop());
				for(int i=m;i<n;i++)
					System.out.println("pop:null");
				System.out.println(stack);
			}
			System.out.println(stack.getClass().getInterfaces()[0]);
		
		}
		}
	}
}